package com.sanda.androidcourse.chapter06;

import static android.content.Context.MODE_PRIVATE;

import android.content.SharedPreferences;

public class SharedPreferencesHelper {
    /**
     * 写入SharedPreferences
     */
    public static void writeSharedPreferences(FileStorageActivity fileStorageActivity, String test, String s) {
        SharedPreferences sharedPreferences = fileStorageActivity.getSharedPreferences("test", MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(test, s);
        editor.apply();
    }

    /**
     * 读取SharedPreferences
     */
    public static String readSharedPreferences(FileStorageActivity fileStorageActivity, String test) {
        SharedPreferences sharedPreferences = fileStorageActivity.getSharedPreferences("test", MODE_PRIVATE);
        return sharedPreferences.getString(test, "");
    }

    /**
     * 删除SharedPreferences
     */
    public static void deleteSharedPreferences(FileStorageActivity fileStorageActivity, String test) {
        SharedPreferences sharedPreferences = fileStorageActivity.getSharedPreferences("test", MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.remove(test);
        editor.apply();
    }
}
